home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / aed244a.zip / MOVCSTR.ASM < prev    next >
Assembly Source File  |  1991-02-16  |  6KB  |  176 lines

  1. comment @
  2.  
  3.  *  MOVECURSTR
  4.  *----------------------------------------------------------------------------
  5.  *
  6.  *  Routine to generate an ANSI move cursor string
  7.  *
  8.  *  Author: Tom Collins
  9.  *          09-20-90
  10.  *
  11.  *  Calling Sequence:
  12.  *
  13.  *     A$ = SPACE$(8)
  14.  *     CALL MoveCurStr(OldY, OldX, NewY, NewX, A$, ALen)
  15.  *     A$ = LEFT$(A$, ALen)
  16.  *     Call QuickTput(A$, 0)
  17.  *
  18.  *  Returns:
  19.  *     ANSI string in A$
  20.  *     Length of string in ALen
  21.  *     OldX = NewX
  22.  *     OldY = NewY
  23.  *
  24.  *  Assemble with: TASM movcstr.asm [/Zi]   or,
  25.  *                 MASM movcstr.asm [/Zi]
  26.  *  (Zi = Debug info for CV)
  27.  *
  28.     @
  29.  
  30.        .MODEL MEDIUM, BASIC
  31.  
  32.        .CODE
  33.  
  34.        PUBLIC  MOVECURSTR
  35.        PUBLIC  ITOA
  36.  
  37. ITOA   proc USES bx
  38.  
  39.        mov      bl, 10             ; Divide AX by 10
  40.        div      bl                 ; AL = AX/10, AH = remainder
  41.        and      al, al             ; Set the flags
  42.        jz       IT01               ; Skip first digit if it's zero
  43.        add      al, '0'            ; Not zero.  Convert AL to a character
  44.        stosb                       ; Save it in string
  45.        inc      cx                 ; Correct the length
  46. IT01:  mov      al, ah             ; Get remainder in AL
  47.        add      al, '0'            ; Convert AL to a character
  48.        stosb                       ; Save it in string
  49.        inc      cx                 ; Correct the length
  50. IT02:  ret                         ; Done
  51.  
  52. ITOA   endp
  53.  
  54.  
  55. MOVECURSTR  proc USES es si di, OLDY:ptr, OLDX:ptr, NEWY:ptr, NEWX:ptr, A:ptr, ALEN:ptr
  56.  
  57.        push     ds                 ; Save DS
  58.        pop      es                 ; Set ES = DS
  59.  
  60.        mov      si, A              ; DS:SI -> String descriptor
  61.        mov      di, [si+2]         ; ES:DI -> A$
  62.  
  63. ; Build the ANSI header = ESC [
  64.  
  65.        mov      al, 01Bh           ; AL = ESC
  66.        stosb                       ; Save it to A$
  67.        mov      al, '['            ; AL = '['
  68.        stosb                       ; Save it to A$
  69.        mov      cx, 2              ; CX = New ALEN
  70.  
  71. ; Get NEWX and NEWY in AL and AH
  72.  
  73.        mov      si, NEWX           ; DS:SI -> NEWX
  74.        mov      al, [si]           ; AL = NEWX
  75.        mov      si, NEWY           ; DS:SI -> NEWY
  76.        mov      ah, [si]           ; AH = NEWY
  77.  
  78. ; See if NEWX = NEWY = 0
  79.  
  80.        and      ax, ax             ; Set the flags
  81.        jz       MC15               ; NEWX = NEWY = 0.  Return.
  82.  
  83.        cmp      ax, 0101h          ; See if NEWX = NEWY = 1
  84.        jnz      MC02               ; No
  85.  
  86. ; NEWX = NEWY = 1.  Set string to ESC [f
  87.  
  88.        mov      BYTE PTR[di], 'f'  ; Set up the A$ string
  89.        inc      cx                 ; Set length equal to 3
  90.        jmp      short MC16         ; Return
  91.  
  92. ; Get the differences between the OLD and NEW strings in AX
  93.  
  94. MC02:  mov      si, OLDX           ; DS:SI -> OLDX
  95.        sub      al, [si]           ; AL = NEWX - OLDX
  96.        mov      si, OLDY           ; DS:SI -> OLDY
  97.        sub      ah, [si]           ; AH = NEWY - OLDY
  98.  
  99. ; See whether the X or Y or both changed.
  100.  
  101.        and      ax, ax             ; Set the flags
  102.        jz       MC15               ; Neither changed
  103.  
  104.        and      al, al             ; Set the flags
  105.        jz       MC03               ; X didn't change.  Just Y.
  106.  
  107.        and      ah, ah             ; X changed.  See if Y did.
  108.        jz       MC05               ; No
  109.  
  110. ; Both X and Y changed.  Build a string containing ESC [ NEWY ; NEWX f
  111.  
  112.        mov      si, NEWY           ; DS:SI -> NEWY
  113.        mov      ax, [si]           ; AX = NEWY
  114.        call     ITOA               ; Convert NEWY to a string
  115.        mov      al, ';'            ; Add the semicolon
  116.        stosb                       ;
  117.        mov      si, NEWX           ; DS:SI -> NEWX
  118.        mov      ax, [si]           ; AX = NEWX
  119.        call     ITOA               ; Convert NEWX to a string
  120.        mov      BYTE PTR [di], 'f' ; Add the trailing character
  121.        add      cx, 2              ; Correct the string length
  122.        jmp      short MC16         ; Done
  123.  
  124. ; Just the Y coordinate changed.  Build ESC [ nn B (or A)
  125.  
  126. MC03:  mov      si, OLDY           ; DS:SI -> OLDY
  127.        mov      ax, [si]           ; AX = OLDY
  128.        mov      si, NEWY           ; DS:SI -> NEWY
  129.        sub      ax, [si]           ; AX = OLDY - NEWY
  130.        mov      bl, 'A'            ; Trailing character is 'A' (move up)
  131.        jmp      short MC06         ; Do the string
  132.  
  133. ; Just the X coordinate changed.  Build ESC [ nn C (or D)
  134.  
  135. MC05:  mov      si, NEWX           ; DS:SI -> NEWX
  136.        mov      ax, [si]           ; AX = NEWX
  137.        mov      si, OLDX           ; DS:SI -> OLDX
  138.        sub      ax, [si]           ; AX = NEWX - OLDX
  139.        mov      bl, 'C'            ; Trailing character is 'C' (move right)
  140.  
  141. MC06:  cmp      ax, 0              ; See if AX is positive
  142.        jg       MC07               ; Yes
  143.        neg      ax                 ; No.  Make it positive
  144.        add      bl, 1              ; Increment trailing character
  145. MC07:  call     ITOA               ; Convert AX to a string
  146.        mov      [di], bl           ; Add the trailing character
  147.        inc      cx                 ; Correct the length of CX
  148.        jmp      short MC16         ; Return
  149.  
  150. ; One of the coordinates is zero, or no change is required.
  151.  
  152. MC15:  mov      si, ALEN           ; DS:SI -> ALEN
  153.        mov      BYTE PTR[si], 0    ; New ALEN is zero
  154.        ret                         ; Return
  155.  
  156. ; Normal return
  157.  
  158. MC16:  mov      si, ALEN           ; DS:SI -> ALEN
  159.        mov      [si], cx           ; Save CX to ALEN
  160.  
  161.        mov      si, NEWX           ; DS:SI -> NEWX
  162.        mov      al, [si]           ; AL = NEWX
  163.        mov      si, OLDX           ; DS:SI -> OLDX
  164.        mov      [si], al           ; OLDX = NEWX
  165.  
  166.        mov      si, NEWY           ; DS:SI -> NEWY
  167.        mov      al, [si]           ; AL = NEWY
  168.        mov      si, OLDY           ; DS:SI -> OLDY
  169.        mov      [si], al           ; OLDY = NEWY
  170.  
  171.        ret                         ; Return
  172.  
  173. MOVECURSTR   endp
  174.  
  175.         end
  176.